#include "gamewindow.h"

#include <QMessageBox>
#include <QGraphicsView>
#include <QVBoxLayout>
#include "board.h"

GameWindow::GameWindow(QWidget *parent)
    : QWidget(parent)
    , m_board(new Board(400, this))
    , m_points(0)
{
    connect(m_board, SIGNAL(eaten()), this, SLOT(on_eating()));
    connect(m_board, SIGNAL(finish()), this, SLOT(on_finish()));

    QGraphicsView *view = new QGraphicsView(m_board, this);
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(view);
    setLayout(layout);
}

void GameWindow::on_eating()
{
    m_points++;
}

void GameWindow::on_finish()
{
    QMessageBox dialog(QMessageBox::Information
                       , "Game finished"
                       , "Game finished! Your score: " + QString::number(m_points) + "\n"
                       + "Would you like to restart game?"
                       , QMessageBox::No | QMessageBox::Yes);
    if (dialog.exec() == QMessageBox::Yes)
    {
        m_board->reset();
        m_points = 0;
    }
}
